/// @tags: DP Exclusion
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

typedef long long LL;
typedef unsigned long long ull;

int const N = 1e3 + 5, mod = 998244353;

int n, e_cnt;
int heads[N], a[N], b[N], c[N], s[N], f[N][N * 3], siz[N], tmp[N * 3], inv[N * 3];

struct Edge {
  int v, nxt;
  bool typ;
} e[N << 1];

inline void add(int u, int v, bool typ) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].typ = typ;
}

inline int pls(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}

inline int dec(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}

inline int qpow(LL base, int exp) {
  LL res = 1;
  for (; exp; exp >>= 1, base = base * base % mod)
    if (exp & 1) res = res * base % mod;
  return res;
}

inline void dfs(int u, int fa) {
  siz[u] = 1;
  f[u][1] = (LL)a[u] * s[u] % mod;
  f[u][2] = (LL)b[u] * s[u] % mod * 2 % mod;
  f[u][3] = (LL)c[u] * s[u] % mod * 3 % mod;
  for (int i = heads[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa) {
      dfs(v, u);
      for (int j = 1; j <= siz[u] * 3; ++j)
        for (int k = 1; k <= siz[v] * 3; ++k) {
          int res = (LL)f[u][j] * f[v][k] % mod;
          if (e[i].typ) tmp[j + k] = dec(tmp[j + k], res), tmp[j] = pls(tmp[j], res);
          else
            tmp[j + k] = pls(tmp[j + k], res);
        }
      siz[u] += siz[v];
      for (int j = 1; j <= 3 * siz[u]; ++j) f[u][j] = tmp[j], tmp[j] = 0;
    }
  for (int i = 1; i <= siz[u] * 3; ++i) f[u][i] = (LL)f[u][i] * inv[i] % mod;
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= 3 * n; ++i) inv[i] = qpow(i, mod - 2);
  for (int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i] >> c[i], s[i] = qpow(a[i] + b[i] + c[i], mod - 2);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    add(u, v, false), add(v, u, true);
  }
  dfs(1, 1);
  int ans = 0;
  for (int i = 1; i <= siz[1] * 3; ++i) ans = pls(ans, f[1][i]);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P5405 [CTS2019] 氪金手游.in", "r", stdin);
  freopen("P5405 [CTS2019] 氪金手游.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
